<template>
	<div class="port-page">
		<div class="but1">
        <router-link to="/home">
         	<el-button type="warning" size="small" class="add btn" style='margin-right: 10px;' icon="el-icon-menu">首页</el-button>
        </router-link>
        </div>
		<div class="czlx">
			<span style="float: left;"> 出入库类型：</span>
		  <el-checkbox  v-model="qx" style="float: left;margin-right: 5px;" @change="checkall2()" >全选</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vxs"     v-if='xsadd' >销售</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vjh"     v-if='jhadd' >进货</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vth"     v-if='thadd' >退货</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vbs"     v-if='bsadd' >报损</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vly"     v-if='jyadd' >借用</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vtl"     v-if='ghadd' >归还</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vbx"     v-if='bxadd' >报修</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vxf"     v-if='xfadd' >修复</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vkctz"   v-if='kctzadd' >库存调整</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vbssc"   v-if='bsscadd' >报损删除</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vlyck"   v-if='lyckadd' >领用出库</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vlyckth" v-if='lyckthadd' >领用出库退回</el-checkbox>
		  <el-checkbox @change="search()"  v-model="vxsth"   v-if='xsthadd' >销售退回</el-checkbox>
		</div>
		<!-- 模糊搜索条件 -->
		<div class="search">
	    <div class="search-item">
	        <div class="search-item">
		    <el-select v-model="vwpflid" class="code-search" @change="search()" placeholder="请选择物品分类">
					<el-option :label="v.mc" :value="v.id" v-for="v in comboxlist"></el-option>
		    </el-select>
 			</div>
			<div class="search-item">
				<el-input placeholder="请输入物品名称" class="code-search" v-model="vkeyword" @keyup.enter.native="search" icon="search"></el-input>
			</div>
     	</div>
		    <span>数据日期</span>
                <el-date-picker  v-model="vbtime"  :editable="false" type="date" class="code-search"  placeholder="开始日期" @keyup.enter.native="search" icon="search"></el-date-picker>
                <div class="search-item">
                <!--<span>结束时间：</span>-->
                  <el-date-picker  v-model="vetime"  :editable="false" type="date" class="code-search"  placeholder="结束日期" @keyup.enter.native="search" icon="search"></el-date-picker>
            </div>
               <el-button type="primary" class="add btn" style="border-radius:13px;" :loading="searchLoading" @click="search" icon="el-icon-search"></el-button>
            </div>
		<!-- 数据表格展示区域 -->
		<el-table 
			:data="dataList"
			:cell-style="styletest"
			border
            stripe
            size="small"
			align="left"
			class="admin-table"
			@select="checkSelect"
			@select-all="checkall">
			<!--<el-table-column type="selection" width="55"></el-table-column>-->
			<el-table-column label="物品名称" width="100" align="center">
				<template scope="scope">
					<el-button size="small" type="text" style="color:#1F2D3D;text-decoration:underline;background: #BEDBDF;"@click="componentsShow('wpxq',scope)">{{scope.row.wpmc}}</el-button>
				</template>
			</el-table-column>
			<el-table-column label="类型" width="100" align="center">
				<template scope="scope">
					<el-button size="small" type="text"  style="color:#1F2D3D;border-bottom: 1px solid deepskyblue;" @click="componentsShow(scope.row.lxmc,scope)">{{scope.row.lxmc}}</el-button>
					<!--<el-button size="small" type="text"  style="color:#1F2D3D" @click="componentsShow('lxxq',scope)">{{scope.row.lxmc}}</el-button>-->
				</template>
			</el-table-column>
			<div slot='empty'>
				<img src="../../../assets/img/empty.png" style="width:40px;vertical-align: middle;">
				<span style="vertical-align: middle;">暂时还没有内容哦!</span>
			</div>
			<el-table-column :prop="v.prop" :label="v.label" v-for="(v,index) in portTitleList" align="center" show-overflow-tooltip v-if="v.hide != 0" :formatter="v.formatter" :align="v.align || 'center'" :fixed="v.fixed" :class-name="v.columnStyle" :width="v.width" :min-width="v.minWidth" :header-align="v.headerAlign || 'center'">
				<template scope="scope">
					<div slot="reference" :style="tableCellControl(scope)">
						{{ scope.row[scope.column.property] }}
					</div>
				</template>
			</el-table-column>
		</el-table>
		<!-- 分页查询区域 -->
		<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page.sync="pageindex" :page-sizes="pagesizes" :page-size="pagesize" :layout="layout" :total="total" class="class-page">
		</el-pagination>
		<!-- 各个组件显示区域 -->
		<!-- 动画加载 -->
		<LoadingComponent v-show="isLoading"></LoadingComponent>
		<!-- 添加组件 -->
		<AddComponent v-if="portComponents.add.toggle" @close="componentsHide"></AddComponent>
		<!-- 编辑组件 -->
		<EditComponent v-if="portComponents.edit.toggle" @close="componentsHide" :params="portComponents.edit.params"></EditComponent>
		<!-- info组件 -->
		<infoComponent v-if="portComponents.info.toggle" @close="componentsHide" :params="portComponents.info.params"></infoComponent>
		<LxxqComponent v-if="portComponents.lxxq.toggle" @close="componentsHide" :params="portComponents.lxxq.params"></LxxqComponent>
        
		<BtgComponent v-if="portComponents.btg.toggle" @close="componentsHide" :params="portComponents.btg.params"></BtgComponent>
        <WpxqComponent v-if="portComponents.wpxq.toggle" @close="componentsHide" :params="portComponents.wpxq.params"></WpxqComponent>
        <TgComponent v-if="portComponents.tg.toggle" @close="componentsHide" :params="portComponents.tg.params"></TgComponent>
		<!-- 单独删除组件 -->
		<DeleteComponent v-if="portComponents.singleDelete.toggle" @close="componentsHide" :data="portComponents.singleDelete.data"></DeleteComponent>
		<!-- 批量删除组件 -->
		<DeleteComponent v-if="portComponents.multipleDelete.toggle" @close="componentsHide" :data="portComponents.multipleDelete.data"></DeleteComponent>
		<!-- 子路由显示区域 -->
		<router-view class="port-view"></router-view>
	</div>
</template>
<script>
	import { mapState } from 'vuex'
	import LoadingComponent from 'components/loading'
	import AddComponent from './add'
	import EditComponent from './edit'
    import WpxqComponent from 'view/manage/kccx/wpxq'
	import InfoComponent from '../../cost/payjl/info'
	import BtgComponent from './btg'
    import TgComponent from './tg'
    import LxxqComponent from './lxxq'
	import DeleteComponent from './del'
	import qs from 'qs'
	export default {
 		props: ['params'],
		components: { LoadingComponent,WpxqComponent,LxxqComponent, DeleteComponent,BtgComponent, AddComponent, TgComponent, EditComponent, InfoComponent },
		data() {
			return {
				xsadd:true,
				jhadd:true,
				thadd:true,
				bsadd:true,
				jyadd:true,
				ghadd:true,
				bxadd:true,
				xfadd:true,
				kctzadd:true,
				bsscadd:true,
				lyckadd:true,
				lyckthadd:true,
				xsthadd:true,
				wpfl:'',
				wpfl1:'',
				vetime:'',
				vbtime:'',
				vwpflid:'',
				qx:'',
				dxsz:'',
				vbs:false,
				vbx:false,
				vxf:false,
				vjh:false,
				vth:false,
				vly:false,
				vtl:false,
				vxs:true,
				vkctz:false,
				vbssc:false,
				vlyck:false,
				vlyckth:false,
				vxsth:false,
				/*模糊搜索条件*/
				vkeyword: '', // 关键字报损原因
				multipleDelNum: '', //获取批量选择的数据
				dataList: [], //表格数据
				comboxlist: [], //下拉框 动态的
                visqy:'N',
 				/*动画加载*/
				isLoading: true, //动画加载
				searchLoading: false, //搜索按钮触发按钮动画
				/*分页属性设置*/
				layout: 'total, sizes, prev, pager, next, jumper', //组件布局
				pageindex: this.$store.state.pageindex, //当前分页页码
				pagesizes: this.$store.state.pagesizes, //显示个数的选择器选项
				pagesize: this.$store.state.pagesize, //每页显示条目数
				total: 0, //总条数

				/*组件区域*/
				portComponents: {
					/* 单行删除  */
					singleDelete: {
						type: 'singleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'single',
							title: '此操作将删除该记录?, 是否继续?'
						}
					},
					/* 批量删除 */
					multipleDelete: {
						type: 'multipleDelete',
						toggle: false,
						params: '',
						data: {
							index: '',
							type: 'multiple',
							title: '此操作将删除您选中的记录?, 是否继续?'
						}
					},
					/* 添加 */
					add: {
						type: 'add',
						toggle: false,
						params: '',
						data: {}
					},
					/* 编辑 */
					edit: {
						type: 'edit',
						toggle: false,
						params: '',
						data: {}
					},
					/* info */
					info: {
						type: 'info',
						toggle: false,
						params: '',
						data: {}
					},
					btg: {
                        type: 'btg',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    tg: {
                        type: 'tg',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    lxxq: {
                        type: 'lxxq',
                        toggle: false,
                        params: '',
                        data: {}
                    },
                    wpxq: {
                        type: 'wpxq',
                        toggle: false,
                        params: '',
                        data: {}
                    }
				},
				/*
				    prop :  接口参数名
				    label : 接口中文名
				    hide : 是否隐藏这一列
				    align : 这一列对齐顺序 ： left,right,center
				    headerAlign : 这一列表头对齐方式 ： left,right,center
				*/
				portTitleList: [
					{
						prop: 'id',
						label: '',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpid',
						label: '物品id',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'wpmc',
						label: '物品名称',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},{
						prop: 'wpflmc',
						label: '物品分类',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '100',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'lxmc',
						label: '类型',
						hide: 0,
						align: 'center',
						fixed: false,
						width: '100',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'sl',
						label: '数量',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '100',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'sj',
						label: '时间',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '150',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					},
					{
						prop: 'note',
						label: '进出库说明',
						hide: 1,
						align: 'center',
						fixed: false,
						width: '',
						minWidth: '',
						headerAlign: 'center',
						formatter: function(row, column) {}
					}
				]
			}
		},
		created() {
			 this.wpfl1 =this.params;
			 this.wpfl =this.params;
             var vpage =this.params;
			//加载页面时调用
			if(vpage == '12'){
                     this.$store.dispatch('changeTitle','教材、学习用品类进出库查询');//修改title
                     this.bxadd=false
                     this.bsscadd=false 
                     this.xfadd=false 
                     this.lyckthadd=false
            }else if(vpage == '3'){
                     this.$store.dispatch('changeTitle','固定资产类进出库查询');//修改title
            }else if(vpage == '4'){
                     this.$store.dispatch('changeTitle','易耗品类进出库查询');//修改title
                     this.jyadd=false
                     this.ghadd=false
                     this.bsadd=false
                     this.bxadd=false
//                   this.xsthadd=false
            }else{
                  this.$store.dispatch('changeTitle','进出库查询');//修改title
            }
			this.$store.dispatch('changeRouterIndex', '/manage/jckcx'); //修改路由
			this.visqy='N';
		
			this.isLoading = true; //动画开始

			if(this.$route.query.frompagetwo){
				this.wpfl=this.$route.query.frompagetwo;
				if(vpage == '12'){
            	this.$store.dispatch('changeTitle','教材、学习用品类进出库查询');//修改title
            }
            }
			else{
                this.wpfl=this.$route.query.frompage;
            }
			if(this.$route.query.frompagetwo){
				this.wpfl=this.$route.query.frompagetwo;
				if(vpage == '3'){
            	this.$store.dispatch('changeTitle','固定资产类进出库查询');//修改title
            }
            }
			else{
                this.wpfl=this.$route.query.frompage;
            }
			if(this.$route.query.frompagetwo){
				this.wpfl=this.$route.query.frompagetwo;
				if(vpage == '4'){
            	this.$store.dispatch('changeTitle','易耗品类进出库查询');//修改title
            }
            }
			else{
                this.wpfl=this.$route.query.frompage;
            }
            	this.search(); //分页获取默认数据
			this.getcomboxlist(); //加载下拉列表
		},
		mounted() {
			//加载完成之后event
			this.isLoading = false; //动画结束
		},
		methods: {
			styletest(boj){
				if (boj.columnIndex==3){
					if (this.dataList[boj.rowIndex].sl<=0){
					 return 'color:red'
				  }
				}
				return '';
			},
//			styletest(boj){
//             console.log(boj,'23')
//          if(this.dataList[boj.rowIndex].ztmc == '不通过'){
//            return ' background:#DBD6D6'
//          }
//  				return '';
//  			},
			 getcomboxlist(){
				var logininfo = JSON.parse(localStorage.logininfo) ;
				var params3 = qs.stringify({
					yhid:logininfo.id,
					xxid:logininfo.xxid,
					wpfl:this.params
				});
					this.searchLoading = true;
					this.axios.post(this.$store.state.api + 'wpfl/getlist',params3)
					.then( res => {
							let data = res.data.data;
							let list = data.list;
							this.comboxlist=list;
					}).catch( res => {
							this.searchLoading = false;
					})
			},
			search() {
				//查询搜索触发事件
	  			  var time1 = this.$.getLocalTimeNo0(Date.parse(this.vbtime));
	              var time2 = this.$.getLocalTimeNo0(Date.parse(this.vetime));
	              var logininfo = JSON.parse(localStorage.logininfo) ;
							var params3 = qs.stringify({
								keyword: this.vkeyword, // 物品名称
								btime:time1, //
								etime: time2, //
								wpflid: this.vwpflid,
								jh: this.vjh?'Y':'N', // 进货
								th: this.vth?'Y':'N', // 退货
								bs: this.vbs?'Y':'N', // 报损
								ly: this.vly?'Y':'N', // 领用
								tl: this.vtl?'Y':'N', // 退领
								bx: this.vbx?'Y':'N', // 报修
								xf: this.vxf?'Y':'N', // 修复
								kctz: this.vkctz?'Y':'N', // 库存调整
								xs: this.vxs?'Y':'N', // 销售
								bssc: this.vbssc?'Y':'N', // 报损删除
								lyck: this.vlyck?'Y':'N', // 报损删除
								lyckth: this.vlyckth?'Y':'N', // 报损删除
								xsth: this.vxsth?'Y':'N', // 报损删除
								lytl: this.vlytl?'Y':'N', // 借用与归还
						        wpfl:this.wpfl1,
								yhid:logininfo.id,
								xxid:logininfo.xxid,
								pageindex: this.pageindex,
								pagesize: this.pagesize
							});
		              this.searchLoading = true;
		              this.axios.post(this.$store.state.api + 'jccx/list',params3)
							.then( res => {
			                  let data = res.data.data;
			                  let list = data.list;
			                  this.total = data.totalPage;
			                  this.dataList = list;
			                  this.searchLoading = false;
              }).catch( res => {
                  this.searchLoading = false;
              })
			},
			tableCellControl(scope) {
				//表格单元格控制CSS样式
			},
			handleSizeChange(val) { //每页显示条数触发事件
				this.pagesize = val;
				this.pageindex = 1;
				this.search();
			},
			handleCurrentChange(val) { //分页触发事件
				this.search();
			},
			checkSelect(selection, row) { //点击单选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			checkall2() { //点击全选select触发事件
				 	 this.vjh =this.qx ;// 进货
				 	  this.vth=this.qx ; // 退货
				 	  this.vbs=this.qx ;
				 	  this.vly=this.qx ;
				 	  this.vtl=this.qx ;
				 	  this.vbx=this.qx ;
				 	  this.vxf=this.qx ;
				 	  this.vkctz=this.qx ;
				 	  this.vxs =this.qx ;
				 	  this.vbssc =this.qx ;
				 	  this.vlyck =this.qx ;
				 	  this.vlyckth =this.qx ;
				 	  this.vxsth =this.qx ;
				 	  this.vlytl =this.qx ;
				 	  
					  this.search();
			},
			checkall(selection) { //点击全选select触发事件
				let strID = [];
				selection.forEach(function(v, i) {
					strID.push(v.id)
				})
				this.multipleDelNum = strID.join(",");
			},
			/* 组件的弹框  */
			componentsShow(type, data) { //显示组件
				if(type == 'wpxq'){
					this.portComponents.wpxq.toggle = true
				}
				
				else if(type == '销售'){
					this.portComponents.info.toggle = true
					this.portComponents.info.params = data;
				}else{
					this.portComponents.lxxq.toggle = true
					this.portComponents.lxxq.params = data;
				}
				for(let i in this.portComponents) {
					if(type == this.portComponents[i].type) {
						this.portComponents[i].toggle = true;
						this.portComponents[i].params = data;
						if(this.portComponents[i].data.type == 'single') {
							this.portComponents[i].data.index = data.row.id
						} else if(this.portComponents[i].data.type == 'multiple') {
							this.portComponents[i].data.index = this.multipleDelNum;
						} else {
							return;
						}
						return;
					}
				}
			},
			componentsHide(setting) { //关闭组件
				for(let i in this.portComponents) {
					if(setting.type == this.portComponents[i].type) {
						this.portComponents[i].toggle = false;
						if(!setting.cancel) {
							this.search();
						}
						return;
					}
				}
			}
		},
		computed: {
			...mapState([
				'api' //域名
			]),
			multipleDeleteDisabled() {
				if(this.multipleDelNum) {
					return false;
				} else {
					return true
				}
			}
		}
	}
</script>

<style lang="less" scoped>
	.port-page {
		width: 96%;
		font-size: 12px;
		position: absolute;
		.btn {
			height: 30px;
			padding: 0 10px;
		}
		.code-search {
			 max-width: 130px;
            min-width: 100px;
            text-align: center;
            height: 50px;
            /*line-height: 50px;*/
            font-size: 12px;
		}
		.class-page {
			text-align: left;
			margin-top: 10px;
		}
		.search-item {
			display: inline-block;
		}
		 .but1{
			width: 100%;
			float: left;
		}
		.search{
			width: 100%;
			height: 50px;
			line-height: 50px;
			float: left;
			text-align: left;
		}
		.czlx{
			width: 100%;
			height: 34px;
			line-height: 34px;
			float: left;
		}
		.el-checkbox {
		    color: #5a5e66;
		    font-weight: 500;
		    font-size: 14px;
		    cursor: pointer;
		    user-select: none;
        }
        .el-checkbox+.el-checkbox {
    margin-left: 5px;
}
		.el-button+.el-button {
            margin-left: 0px;
            margin-top: 8px;
        }
	}
</style>
